﻿using Data.Entity.Test;
using Infra.CustomException;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL.Database.EasierMVC.DB.EF.Schema
{
    public class DatabaseContext : DbContext
    {
        #region Constructors
        public DatabaseContext(Action<string> log)
            : this("DatabaseContext", log)
        { }

        public DatabaseContext(string connectionstring, Action<string> log)
            : base(connectionstring)
        {
            if(log != null)
                base.Database.Log = a => log(a);
        }
        #endregion

        public override int SaveChanges()
        {
            try
            {
                return base.SaveChanges();
            }
            catch (Exception e)
            {
                throw new DalException(e);
            }
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<Person> Person { get; set; }
        public DbSet<Country> Coutnry { get; set; }
    }
}
